/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author cpn02
 */
import ActionForm.*;
import bean.*;
import Model.*;
import javax.servlet.http.HttpSession;
public class LoginAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        LoginForm lg = (LoginForm)form;
        Customer cus = CusModel.getCustomer(lg.getUserName(), lg.getPassw());
        if(cus==null)
        {
            String mess = "Ban da nhap sai usernam hoac password" ;
            request.setAttribute("failLogin",mess);
            return mapping.findForward("fail");
        }
        else
        {
            request.getSession().setAttribute("customer", cus);
            return mapping.findForward("success");
        }
    }


}
